<?php
declare (strict_types = 1);

namespace app\api\controller;
use app\model\ProductSalesSpecsModel;
use app\model\ProductsModel;
use think\App;

class Products extends Base {

    private $productsModel;

    private $req;

    private $product_id;

    public function __construct(App $app)
    {
        parent::__construct($app);

        $this->req = request()->param();

        $this->page = isset($this->req['page']) ? $this->req['page'] : 1;

        $this->product_id = isset($this->req['product_id']) ? $this->req['product_id'] : "";

        $this->productsModel = new ProductsModel();
    }



    /*
     * 商品详情表
     *
     * */
    public function getProductDetail(){
        if(!$this->product_id){
            return $this->fail("商品Id 不能为空");
        }


        $info = $this->productsModel->getInfo($this->product_id);

        //增加浏览量
        $this->productsModel->incrProductViewNum($this->product_id);


        return $this->succ($info);

    }


    /*
   * 商品详情表
   *
   * */
    public function getProductSalesSpecsList(){
        if(!$this->product_id){
            return $this->fail("商品Id 不能为空");
        }

        $list = (new ProductSalesSpecsModel())->getProductSalesSpecsList($this->product_id);

        return $this->succ($list);

    }


    /*
     * 猜你喜欢 随机取4条数据
     * */
    public function getGuessYouLikeProducts(){

        $product_id = isset($this->req['product_id']) ? $this->req['product_id'] : 0;

        $info = $this->productsModel->getGuessYouLike($product_id);

        return $this->succ($info);
    }


}
